package o;

import android.content.Intent;
import android.text.TextUtils;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class dgk implements eqg {
    public static void ॱ() {
        eqi.ˏ().ˎ("StoreUserBirthObserver", new dgk());
    }

    private static void ˎ(String str, long j, int i) {
        int ˎ = ˎ(str, j);
        UserSession.getInstance().setUserAge(ˎ);
        if (ˎ >= i) {
            if (Logger.ˎ()) {
                Logger.ˏ("StoreUserBirthObserver", "user is adult");
            }
            UserSession.getInstance().setUserMinor(false);
        } else {
            if (Logger.ˎ()) {
                Logger.ˏ("StoreUserBirthObserver", "user is minor");
            }
            eny.ˊ().ˏ(0);
            UserSession.getInstance().setUserMinor(true);
        }
        Logger.ˏ("StoreUserBirthObserver", "start send refresh broadcast");
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent("com.huawei.appmarket.service.broadcast.AgeAbtained"));
    }

    private static int ˎ(String str, long j) {
        if (TextUtils.isEmpty(str) || j <= 0) {
            Logger.e("StoreUserBirthObserver", "get birthdate null or time: " + j);
            return 18;
        }
        try {
            Date parse = new SimpleDateFormat("yyyyMMdd", Locale.US).parse(str);
            Calendar instance = Calendar.getInstance();
            Calendar instance2 = Calendar.getInstance();
            if (parse == null) {
                return 18;
            }
            Date date = new Date();
            date.setTime(j);
            instance2.setTime(date);
            instance.setTime(parse);
            if (instance.after(instance2)) {
                return 18;
            }
            int i = instance2.get(1) - instance.get(1);
            if (instance2.get(6) < instance.get(6)) {
                return i - 1;
            }
            return i;
        } catch (ParseException e) {
            Logger.e("StoreUserBirthObserver", "birthdate pare error!");
            return 18;
        }
    }

    public void ˎ(String str) {
        if (!TextUtils.isEmpty(str)) {
            cfw.ˎ(new drh("pushInfo"), new c(str));
        } else if (eqp.ᐝ()) {
            UserSession.getInstance().setUserMinor(false);
        } else {
            UserSession.getInstance().setUserMinor(true);
        }
    }
}
